$("#header").load("header.html");
axios.defaults.withCredentials = true;
axios.defaults.baseURL = "http://127.0.0.1:8092";
var path = "http://127.0.0.1:8092/ShopManagement/";

function changeCodePic() {
	$("#vcode").attr("src", path + "user/getVeriFicationCode?time=" + new Date().getTime());
}

function logout() {
	alert(1)
	axios({
		url: "/ShopManagement/user/logout",
		method: "get",
	}).then(function(response) {
		if(response.data) {
			window.location.replace("index.html");
		} else {
			alert("系统出现异常,请不要着急");
		}
	}).catch(function(reason) {
		console.log("请求失败");
	});
}
$.getUrlParam = function(name) {
	var val = null;
	var urlparam = window.location.search.replace("%22","").substr(1, (window.location.search.length));
	var $params = urlparam.split("&");
	for(var i = 0; i < $params.length; i++) {
		if(($params[i]).indexOf(name) >= 0) {
			val = ($params[i].substr($params[i].indexOf("=") + 1));
			//						console.log(name+":"+val);
		}
	}
	return val;
}


var head = new Vue({
	el: "#head",
	data: {

	},
	methods: {

	},
	mounted: function() {
		axios({
			url: "/ShopManagement/user/login",
			method: "get",
		}).then(function(response) {
			if(response.data.result) {
				$("#loginLine").attr("href", "javascript:void(0)");
				$("#loginLine").css("text-decoration", "none");
				$("#loginLine").html("欢迎您," + response.data.username);
//				$("#shopcart").show();
				$(".logined").show();
				$(".NotLogined").hide();
			} else {
				$("#loginLine").html("登陆");
				$("#loginLine").attr("href", "login.htm");
				$("#loginLine").css("text-decoration", "underline");
//				$("#shopcart").hide();
				$(".logined").hide();
				$(".NotLogined").show();
			}
		}).catch(function(reason) {
			console.log("请求失败");
		});
		//请求网站相关资源
		axios({
			url: "/ShopManagement/category/findall",
			method: "get",
		}).then(function(response) {
			if(response.data != null) {
				var list = response.data;
				for(var i = 0; i < list.length; i++) {
					var category = list[i];
					var childNode = "<li><a href=product_list.htm?cid=" + category.cid + "&Page=1\">" + category.cname + "</a></li>";
					$("#categorylist").append(childNode);
				}
			}
		}).catch(function(reason) {
			console.log("请求失败");
		});

	}
});